﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;

namespace SoccerSimulator5000
{
    public partial class LoadGameForm : Form
    {
        public string fileName { get; set; }
        public LoadGameForm()
        {
            InitializeComponent();
            fileName = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog();
            this.textBox1.Text = openFileDialog.SafeFileName;
            fileName = openFileDialog.SafeFileName;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (fileName != "")
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(DataClass));
                TextReader reader = new StreamReader(this.fileName);




                DataClass theGame;// = new DataClass(2);

                theGame = (DataClass)deserializer.Deserialize(reader);
                reader.Close();

                Game.initialized = theGame.initialized;
                //Game.teamList = theGame.teamList;
                Game.player = theGame.player;

                //Game.season = new Season();
                //Game.season.seasonStandings = new Standings();
                //Game.season.seasonStandings.standings = new List<Team>();

                //Game.season.seasonFixtures = theGame.season.seasonFixtures;
                //foreach (var Team in Game.teamList)
                //{
                //    Game.season.seasonStandings.standings.Add(Team);
                //}


                Game.season = theGame.season;



                Game.schedule = theGame.schedule;
                Game.date = theGame.date;
                Game.random = theGame.random;
                Game.previousSimSpeed = theGame.previousSimSpeed;
                Game.currentRound = theGame.currentRound;
                this.Close();
            }
            else
                MessageBox.Show("Select file first", "No File");
        }
    }
}
